﻿Imports Business
Public Class RecibirPago
    Dim Type As String
    Dim FormaPago As Long

    Private Sub RecibirPago_Activated(sender As Object, e As EventArgs) Handles Me.Activated
        xDato.Focus()
        With cFormaPago
            .DataSource = FormaPagoBL.List
            .ValueMember = "FORMAPAGO"
            .DisplayMember = "DESCRIPCION"
            If FormaPago > 0 Then cFormaPago.SelectedValue = CDec(FormaPago)
        End With
    End Sub

    Public Sub New(ByVal xTitulo As String, ByVal xMonto As Long, Optional ByVal zFormaPago As Long = 0)

        ' Llamada necesaria para el diseñador.
        InitializeComponent()

        ' Agregue cualquier inicialización después de la llamada a InitializeComponent().
        Me.Text = xTitulo
        Me.xDato.Text = xMonto.ToString
        FormaPago = zFormaPago
        Me.xDato.Focus()
    End Sub

    Private Sub xDato_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles xDato.KeyPress
        If e.KeyChar = vbCr Then
            Aceptar()
        End If
        If e.KeyChar = ChrW(Keys.Escape) Then
            Me.Dispose()
        End If
        If Char.IsDigit(e.KeyChar) Then
            e.Handled = False
        ElseIf Char.IsControl(e.KeyChar) Then
            e.Handled = False
        Else
            e.Handled = True
        End If
    End Sub

    Private Sub xDato_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xDato.TextChanged

        Try
            Dim mt As Double = xDato.Text
            xDato.Text = mt.ToString("##,##")
            xDato.Select(xDato.ToString.Length, xDato.ToString.Length)
        Catch ex As Exception
        End Try
        xDato.Focus()
    End Sub
    Public Function GetValue() As Integer
       
        If xDato.TextLength > 0 Then
            Return CDbl(xDato.Text)
        Else
            Return 0
        End If


    End Function
    Public Function GetFpago() As Long

        If cFormaPago.SelectedValue > 0 Then
            Return cFormaPago.SelectedValue
        Else
            Return 0
        End If

    End Function

    Private Sub bAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bAceptar.Click
        Aceptar()
    End Sub

    Private Sub Aceptar()
        If cFormaPago.SelectedIndex < 0 Then
            Util.Mensaje("Debe Seleccionar Forma de Pago")
            cFormaPago.Focus()
            Exit Sub
        End If
        If xDato.Text = "" Then
            ' Util.Mensaje("Debe Ingresar el Valor")
            ' xDato.Focus()
            'Else

        End If
        Me.DialogResult = DialogResult.OK
    End Sub

    Private Sub bCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bCancelar.Click
        Dispose()
    End Sub
End Class